package com.jcl.recruit.core.utils;

import com.jcl.core.security.RequestStatus;
import com.jcl.core.security.SecurityUtils;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @ClassName SecurityUtils
 * @Description TODO
 * @Author yyliu
 * @Date 2018/9/20 19:25
 * @Version 1.0
 **/
public class SecurityUtil {

    /* *
     * @Author yyliu
     * @Description //TODO
     * @Date 13:06 2018/9/21
     * @Param [resp, code]
     * @return void
     **/
    public static void outputError(HttpServletResponse resp, String code){
        String msg = SecurityUtils.returnErrorJsonStr(code, RequestStatus.statusMap.get(code));
        output(resp, msg);
    }

    public static void output(HttpServletResponse resp, String jsonStr){
        PrintWriter out = null;
        try {
            resp.setContentType("application/json");
            out = resp.getWriter();
            out.write(jsonStr);
            out.close();

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(null != out){
                out.close();
            }
        }
    }

}
